package com.xzy.rabbit.demo.helloworld;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.xzy.rabbit.common.util.RabbitUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 简单模式：生产者
 *
 * @author xzy
 * @date 2021年9月23日
 */
class Main {
    private static final String QUEUE_NAME = "hello_world";
    private static final Integer MESSAGE_COUNT = 10;


    /**
     * 自动应答
     */
    public static void main(String[] args) throws IOException, TimeoutException {

        // 1.创建连接
        ConnectionFactory connectionFactory = RabbitUtil.CONNECTION_FACTORY;
        try (Connection connection = connectionFactory.newConnection()) {

            // 2.发布消息
            Producer.produce(connection, QUEUE_NAME, "hello world!");

            // 3.消费消息
            Consumer.consume(connection, QUEUE_NAME);
        }
    }
}
